package web

import (
	"ksd-social-api/commons/base/controller"
	"ksd-social-api/modules/special/model/context"
	"ksd-social-api/modules/special/service"
)

type AdminSpecialBindDetailController struct {
	controller.BaseController
}

var adminSpecialBindDetailService = service.AdminSpecialBindDetailService{}

/*
*
查询老师信息
*/
func (web *AdminSpecialBindDetailController) UpdateFieldById() {
	// 1: 定义一个接受分页信息的上下文
	specialUpdateContext := context.SpecialUpdateContext{}
	// 2: 开始绑定参数
	web.BindJSON(&specialUpdateContext)
	specialUpdateContext.SystemId = web.GetSystemId()
	web.Ok(adminSpecialBindDetailService.UpdateFieldById(specialUpdateContext))
}

/*
*
查询老师信息
*/
func (web *AdminSpecialBindDetailController) SaveUpdateSpecialDetail() {
	// 1: 定义一个接受分页信息的上下文
	specialBindDetailContext := context.SpecialBindDetailContext{}
	// 2: 开始绑定参数
	web.BindJSON(&specialBindDetailContext)
	specialBindDetailContext.SystemId = web.GetSystemId()
	specialBindDetailContext.SystemName = web.GetSystemName()

	if specialBindDetailContext.NoteId.Uint64() > 0 {
		count := adminSpecialBindDetailService.CountSpecialBindDetailNoteCount(specialBindDetailContext)
		if count > 0 {
			web.FailCodeMsg(604, "已绑定")
			return
		}
	}

	if specialBindDetailContext.TeacherId.Uint64() > 0 {
		count := adminSpecialBindDetailService.CountSpecialBindDetailTeacherCount(specialBindDetailContext)
		if count > 0 {
			web.FailCodeMsg(604, "已绑定")
			return
		}
	}

	web.Ok(adminSpecialBindDetailService.SaveUpdateSpecialBindDetail(specialBindDetailContext))
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  根据id删除
 */
func (web *AdminSpecialBindDetailController) DelById() {
	id, _ := web.ParseParamUint64("id")
	web.Ok(adminSpecialBindDetailService.DelById(id, web.GetSystemId()))
}
